|
|
|
|
|
|
|
forgot to insert a diskette or close the drive door. You can use the Resume keyword whenever you are confident that the situation that caused the error has been remedied, and you want to retry the action that caused the error. |
|
|
|
|
|
|
|
|
Let's modify the BASICERR project by adding a new button to the project. Set its Name property to cmdResumeErr and its Caption property to Resume. Now add the Visual Basic code in Listing 14.5 to support the new button's Click event. |
|
|
|
|
|
|
|
|
Listing 14.5. Using the Resume keyword. |
|
|
|
|
|
|
|
|
Private Sub cmdResumeErr_Click()
'
' show resume keyword
'
On Error GoTo LocalErr
'
Dim intValue As Integer
Dim strMsg As String
'
intValue = InputBox("Enter an integer:")
GoTo LocalExit
'
LocalErr:
strMsg = CStr(Err.Number) & " - " & Err.Description
MsgBox strMsg, vbCritical, "cmdResumeErr"
Resume ' try it again
'
LocalExit:
'
End Sub |
|
|
|
|
|
|
|
|
Save and run the project. When you press the Resume button, you are prompted to enter an integer value. If you press the Cancel button or the OK button without entering data (or if you enter a value that is greater than 32,767), you invoke the error handler and receive an error message from Visual Basic (see Figure 14.4). |
|
|
|
|
|
|
|
|
Figure 14.4.
Reporting an error message
from the input box. |
|
|
|
|
|